import random

_str =f'''
{'*'*60}
{'*{:^54}*'.format('中国工商银行')}
{'*{:^54}*'.format('账户管理系统')}
{'*{:^58}*'.format('V1.0')}
{'*'*60}

{'*{:<57}*'.format('1. 开户')}
{'*{:<57}*'.format('2. 存钱')}
{'*{:<57}*'.format('3. 取钱')}
{'*{:<57}*'.format('4. 转账')}
{'*{:<57}*'.format('5. 查询')}
{'*{:<58}*'.format('6. Bye')}
{'*'*60}
'''


def getAddress():
    country = input('输入所属国家：')
    province = input('请输入所属省份：')
    street = input('请输入街道名称：')
    houseNumber = input('请输入门牌号：')

    return f'{country}-{province}-{street}-{houseNumber}'


def bAccountNumber(accountNumber):

    return map.get(accountNumber,None) is not None


def bPassword(accountNumber,password):

    return map[accountNumber]['password'] == password


def moneyFun(accountNumber,money):
    money2 = map[accountNumber]['money']
    ans = True
    if money > money2:
        print('钱不够！')
        ans = False
    else:
        map[accountNumber]['money'] -= money
    return ans


map = {}
bankName = '中国工商银行的昌平支行'
while True:
    print(_str)
    key = input('请输入：').strip()
    if key == '1':
        name = input('请输入姓名：')
        password = input('请输入密码：')
        print('请输入地址!')
        address = getAddress()
        accountNumber = str(random.randrange(10 ** 7, 10 ** 8))
        if map.get(accountNumber,None):
            print('用户已存在！')
        else:
            if len(map.keys()) > 100:
                print('用户库已满！')
            else:
                map[accountNumber] = {
                    'name':name,
                    'password':password,
                    'address':address,
                    'bank':bankName,
                    'money':0,
                }
                print(f'开户成功，你的账号为：{accountNumber}')
    elif key == '2':
        accountNumber = input('请输入账号：')
        money = int(input('请输入存款金额：'))
        if bAccountNumber(accountNumber):
            map[accountNumber]['money'] += money
            print(f'存款成功！余额为{map[accountNumber]["money"]}')
        else:
            print('没有查询到这个用户信息！')
    elif key == '3':
        accountNumber = input('请输入账号：')
        password = input('请输入密码：')
        money = int(input('请输入取款金额：'))
        if bAccountNumber(accountNumber):
            if not bPassword(accountNumber,password):
                print('密码不对！')
            else:
                if moneyFun(accountNumber,money):
                    print(f'取款成功！余额为{map[accountNumber]["money"]}')
        else:
            print('账号不存在')
    elif key == '4':
        fromAN = input('请输入转出的账号：')
        toAn = input('请输入转入的账号：')
        password = input('输入转出账号的密码：')
        money = int(input('输入转出的金额：'))
        if bAccountNumber(fromAN) and bAccountNumber(toAn):
            if bPassword(fromAN,password):
                ans = moneyFun(fromAN,money)
                if ans:
                    map[toAn]['money'] += money
            else:
                print('密码不对！')
        else:
            print('账号不对！')
    elif key == '5':
        accountNumber = input('请输入账号：')
        password = input('输入账号密码：')
        if bAccountNumber(accountNumber):
            if bPassword(accountNumber,password):
                print(f'1. 当前账号{accountNumber}')
                print(f'2. 密码：{map[accountNumber]["password"]}')
                print(f'3. 余额：{map[accountNumber]["money"]}')
                print(f'4. 用户居住地址：{map[accountNumber]["address"]}')
                print(f'5. 当前账户的开户行：{map[accountNumber]["bank"]}')
            else:
                print('密码不正确！')
        else:
            print('该用户不存在！')
    elif key == '6':
        print('退出程序！')
        break
    else:
        print('输入错误')







